﻿using BUGCOME.Model.Auth;
using BUGCOME.Model.Auth.dto;
using BUGCOME.Model.Logs;
using BUGCOME.ServiceCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BUGCOME.Service.Auth.IServices
{
    /// <summary>
    /// 系统登录服务接口，定义登录相关业务逻辑契约
    /// 继承自基础服务接口，提供用户登录日志的基本操作
    /// </summary>
    public interface ILoginService : IBaseService<UserLoginLog>
    {
        /// <summary>
        /// 异步处理账号密码登录
        /// </summary>
        /// <param name="loginBody">登录请求参数（包含用户名、密码等）</param>
        /// <param name="userLoginLog">登录日志实体（用于记录登录信息）</param>
        /// <returns>登录成功后的用户基础信息</returns>
        Task<UserBase> LoginAsync(LoginDto loginBody, UserLoginLog userLoginLog);

        /// <summary>
        /// 异步处理手机号验证码登录
        /// </summary>
        /// <param name="phoneLoginDto">手机登录请求参数（包含手机号、验证码等）</param>
        /// <param name="userLoginLog">登录日志实体</param>
        /// <param name="user">用户基础信息（可选，用于绑定场景）</param>
        /// <returns>登录成功后的用户基础信息</returns>
        Task<UserBase> PhoneLoginAsync(PhoneLoginDto phoneLoginDto, UserLoginLog userLoginLog, UserBase user);

        /// <summary>
        /// 异步校验用户手机号是否存在
        /// </summary>
        /// <param name="dto">请求参数（包含手机号和用户类型）</param>
        /// <returns>true-手机号已注册；false-手机号未注册</returns>
        Task<bool> CheckUserMobileIsExistAsync(MobileCodeDto dto);

        /// <summary>
        /// 异步查询登录日志列表（带分页）
        /// </summary>
        /// <param name="logininfoDto">查询条件（包含状态、时间范围等）</param>
        /// <returns>分页包装的登录日志集合</returns>
        Task<PagedInfo<UserLoginLog>> GetLoginLogAsync(LogininfoQueryDto logininfoDto);

        /// <summary>
        /// 异步记录登录日志信息
        /// </summary>
        /// <param name="userLoginLog">登录日志实体（已填充完整信息）</param>
        Task AddLoginInfoAsync(UserLoginLog userLoginLog);

        /// <summary>
        /// 异步清空所有登录日志（危险操作）
        /// </summary>
        Task TruncateLogininfoAsync();

        /// <summary>
        /// 异步批量删除登录日志
        /// </summary>
        /// <param name="ids">待删除日志的ID数组</param>
        /// <returns>成功删除的记录数</returns>
        Task<long> DeleteUserLoginLogByIdsAsync(long[] ids);

        /// <summary>
        /// 检查用户是否被锁定
        /// </summary>
        /// <param name="userName">待检查的用户名</param>
        
        void CheckLockUser(string userName);

        /// <summary>
        /// 异步查询登录日志统计数据
        /// </summary>
        /// <returns>按日期分组的登录统计结果（包含总次数、去重次数等）</returns>
        Task<List<StaticLoginLogDto>> GetStatiLoginlogAsync();

        /// <summary>
        /// 检查账号是否锁定
        /// </summary>
        /// <param name="userName">用户名</param>
        /// <returns></returns>
        void CheckLoginLock(string userName);
        /// <summary>
        ///  记录登录失败次数
        /// </summary>
        /// <param name="userName"></param>
        void RecordLoginFail(string userName);

        /// <summary>
        ///  重置失败次数与锁定状态
        /// </summary>
        /// <param name="userName"></param>
        void ResetLoginFailCount(string userName);
    }
}
